package com.tomorrow.runner.service.impl;

import android.content.Context;

import com.tomorrow.runner.service.IBasicService;

import java.util.HashMap;
import java.util.Map;

/**
 * 服务管理者
 * Created by tomorrow on 16-4-27.
 */
public class ServiceManager implements IBasicService {

    public static final int ACCOUNT_SERVICE = 1;


    private static ServiceManager mInstance = new ServiceManager();
    public synchronized static ServiceManager getInstance() {
        return mInstance;
    }
    private ServiceManager(){
    }
    public Context mContext;
    private Map<Integer,IBasicService> mServiceList;
    public void initService(Context context){
        mContext = context;
        mServiceList = new HashMap<>();
        mServiceList.put(ACCOUNT_SERVICE , new AccountService(this));
    }

    public Object getService(int id){
        return mServiceList.get(id);
    }
    @Override
    public void onLogin(String username) {
        for (IBasicService service : mServiceList.values()){
            service.onLogin(username);
        }
    }

    @Override
    public void onLogout(String username) {
        for (IBasicService service : mServiceList.values()){
            service.onLogout(username);
        }
    }
}
